package com.base.component.ai.workflow.result;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.base.component.ai.agent.bo.ContextBO;
import com.base.component.ai.agent.bo.ContextParamBO;

@Component
public class NodeResultTemplate<MSG,AP extends ContextParamBO,PP> {

	private static final String TYPE="type";
	
	@Autowired
	private List<NodeResult<MSG,AP,PP>> resultHandles;
	
	public void execute(ContextBO<MSG,AP,PP> context,Map<String,Object> params) {
		String type=String.valueOf(params.getOrDefault(TYPE, "text"));
		if(params.containsKey(TYPE)) {
			params.remove(TYPE);
		}
		for(NodeResult<MSG,AP,PP> result: resultHandles) {
			if(result.support(type)) {
				result.execute(context, params);
			}
		}
	}
	
}
